package load;

public class LoadClassTest {
    public static void main(String[] args) {
//        ClassLoader loader = LoadClassTest.class.getClassLoader();
//        System.out.println("loader == " + loader);
        CustomClassLoader loader = new CustomClassLoader();
        loader.setRoot("/Users/guangjing.feng.o/github/ListNodeDemo/out/production/ListNodeDemo/");
        try {
            //使用ClassLoader.loadClass()来加载类，不会执行初始化块
            Class cls = loader.findClass("load.Hot");
            //使用Class.forName()来加载类，默认会执行初始化块
//            Class cls = Class.forName("load.Hot");
            System.out.println("cls == " + cls.toString());
            try {
                Hot obj = (Hot) cls.newInstance();
                System.out.println("obj == " + obj.toString());
                obj.test();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            //使用Class.forName()来加载类，并指定ClassLoader，初始化时不执行静态块
//            Class cls = Class.forName("load.Hot", false, loader);
//            System.out.println("cls == " + cls.toString());

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
